package system.task.logger;

import org.springframework.util.StringUtils;
import system.task.config.TaskConfig;

import java.io.File;

/**
 * 任务标准日志输写器
 */
public class TaskLoggerStdWriter extends TaskLoggerFileWriter {
    public TaskLoggerStdWriter(TaskConfig taskConfig, String runId) {
        super(taskConfig, path(taskConfig.getLogPath(), runId));
    }

    private static String path(String p, String runId) {
        if (!StringUtils.hasText(p))
            return null;
        if (!p.endsWith("/") && !p.endsWith("\\"))
            p = p + File.separator;
        p = p + runId.substring(0, 2) + File.separator + runId.substring(2, 4) + File.separator + runId + ".log";
        return p;
    }

}
